package com.swjd.sbm.controller;


import com.swjd.sbm.commons.Constant;
import com.swjd.sbm.commons.ServiceException;
import com.swjd.sbm.entity.Api_chepai;
import com.swjd.sbm.service.HotService;
import com.swjd.sbm.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Slf4j
public class HotController {


    @Autowired
    private HotService HotService;

    @RequestMapping("getlist")
    public Map<String,Object> seke(HttpServletRequest request, HttpServletResponse response,@RequestBody Map<String,String> reqbody) {
        response.setContentType("text/html;charset=utf-8");
        /* 设置响应头允许ajax跨域访问 */
        response.setHeader("Access-Control-Allow-Origin", "*");
        /* 星号表示所有的异域请求都可以接受， */
        response.setHeader("Access-Control-Allow-Methods", "GET,POST");

        int page = Integer.parseInt(reqbody.get("page"));
        int pagesize = Integer.parseInt(reqbody.get("pagesize"));
        String status =reqbody.get("status");

        Map<String,Object> map = new HashMap<>();
        List<Map<String,Object>> list = HotService.getList((page-1)*pagesize,page*pagesize,status);


        map.put("data",list);
        map.put("statusCode",200);
        return map;
    }

    @RequestMapping("getopenid")
    public  Map<String,Object>   getopenid(HttpServletRequest request, HttpServletResponse response,@RequestBody Map<String,String> reqbody) {
        response.setContentType("text/html;charset=utf-8");
        /* 设置响应头允许ajax跨域访问 */
        response.setHeader("Access-Control-Allow-Origin", "*");
        /* 星号表示所有的异域请求都可以接受， */
        response.setHeader("Access-Control-Allow-Methods", "GET,POST");

        String code = reqbody.get("code");

        System.out.println(code);
        Map<String,Object> map = new HashMap<>();

        map.put("openid","moren123456789");  map.put("statusCode","200");

        return  map;

    }
}
